package cn.iocoder.yudao.module.biz.service.contract.expense;

import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;

import java.util.*;
import cn.iocoder.yudao.module.biz.controller.admin.contract.expense.vo.*;
import cn.iocoder.yudao.module.biz.dal.dataobject.contract.expense.ContractArchiveExpenseDO;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;

import cn.iocoder.yudao.module.biz.dal.mysql.contract.expense.ContractArchiveExpenseMapper;

import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertList;
import static cn.iocoder.yudao.module.biz.enums.ErrorCodeConstants.*;

/**
 * 合同档案-支出 Service 实现类
 *
 * @author 超级管理员
 */
@Service
@Validated
public class ContractArchiveExpenseServiceImpl implements ContractArchiveExpenseService {

    @Resource
    private ContractArchiveExpenseMapper bizContractArchiveExpenseMapper;

    @Override
    public Long createContractArchiveExpense(ContractArchiveExpenseSaveReqVO createReqVO) {
        // 插入
        ContractArchiveExpenseDO bizContractArchiveExpense = BeanUtils.toBean(createReqVO, ContractArchiveExpenseDO.class);
        bizContractArchiveExpenseMapper.insert(bizContractArchiveExpense);

        // 返回
        return bizContractArchiveExpense.getId();
    }

    @Override
    public void updateContractArchiveExpense(ContractArchiveExpenseSaveReqVO updateReqVO) {
        // 校验存在
        validateContractArchiveExpenseExists(updateReqVO.getId());
        // 更新
        ContractArchiveExpenseDO updateObj = BeanUtils.toBean(updateReqVO, ContractArchiveExpenseDO.class);
        bizContractArchiveExpenseMapper.updateById(updateObj);
    }

    @Override
    public void deleteContractArchiveExpense(Long id) {
        // 校验存在
        validateContractArchiveExpenseExists(id);
        // 删除
        bizContractArchiveExpenseMapper.deleteById(id);
    }

    @Override
        public void deleteContractArchiveExpenseListByIds(List<Long> ids) {
        // 删除
        bizContractArchiveExpenseMapper.deleteByIds(ids);
        }


    private void validateContractArchiveExpenseExists(Long id) {
        if (bizContractArchiveExpenseMapper.selectById(id) == null) {
            throw exception(BIZ_CONTRACT_ARCHIVE_EXPENSE_NOT_EXISTS);
        }
    }

    @Override
    public ContractArchiveExpenseDO getContractArchiveExpense(Long id) {
        return bizContractArchiveExpenseMapper.selectById(id);
    }

    @Override
    public PageResult<ContractArchiveExpenseDO> getContractArchiveExpensePage(ContractArchiveExpensePageReqVO pageReqVO) {
        return bizContractArchiveExpenseMapper.selectPage(pageReqVO);
    }

}